﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using MuseLibrary.Packets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MuseLibraryTests
{
    [TestClass]
    public class PacketsTests
    {
        [TestMethod]
        public void CanMakePackets()
        {
            for (int i = 0; i <= 255; i++)
            {
                var packet = PacketFactory.MakePacket(i);
                if (packet != null)
                    packet.ReadByte(i);
                switch (i >> 4)
                {
                    case 0x9:
                        Assert.AreEqual(PacketType.DrlRef, packet.Type);
                        Assert.AreEqual(typeof(DrlRefPacket), packet.GetType());
                        if (i != 0x9 << 4)
                            Assert.AreEqual(true, packet.HasFlags);
                        break;
                    case 0xA:
                        Assert.AreEqual(PacketType.Accelerometer, packet.Type);
                        Assert.AreEqual(typeof(AccelerometerPacket), packet.GetType());
                        if (i != 0xA << 4)
                            Assert.AreEqual(true, packet.HasFlags);
                        break;
                    case 0xB:
                        Assert.AreEqual(PacketType.Battery, packet.Type);
                        Assert.AreEqual(typeof(BatteryPacket), packet.GetType());
                        if (i != 0xB << 4)
                            Assert.AreEqual(true, packet.HasFlags);
                        break;
                    case 0xC:
                        Assert.AreEqual(PacketType.CompressedEeg, packet.Type);
                        Assert.AreEqual(typeof(CompressedEegPacket), packet.GetType());
                        if (i != 0xC << 4)
                            Assert.AreEqual(false, packet.HasFlags);
                        break;
                    case 0xD:
                        Assert.AreEqual(PacketType.ErrorFlags, packet.Type);
                        Assert.AreEqual(typeof(ErrorPacket), packet.GetType());
                        if (i != 0xD << 4)
                            Assert.AreEqual(true, packet.HasFlags);
                        break;
                    case 0xE:
                        Assert.AreEqual(PacketType.UncompressedEeg, packet.Type);
                        Assert.AreEqual(typeof(UncompressedEegPacket), packet.GetType());
                        if (i != 0xE << 4)
                            Assert.AreEqual(true, packet.HasFlags);
                        break;
                    case 0xF:
                        if (i == 255)
                        {
                            Assert.AreEqual(PacketType.Synchronisation, packet.Type);
                            Assert.AreEqual(typeof(SynchronisationPacket), packet.GetType());
                        }
                        break;
                    default:
                        Assert.AreEqual(null, packet);
                        break;
                }
            }
        }
    }
}
